import {
  ILogger,
} from './prefetcher';
import hilog from '@ohos.hilog';

const DOMAIN = 0x0000;
const TAG = "lib-prefetch";
const FORMAT = '%{public}s';

export class Logger implements ILogger {
  private static counter = 0;

  private readonly traceId = ++Logger.counter;
  private readonly messagePrefix: string;

  constructor(messagePrefix?: string) {
    this.messagePrefix = messagePrefix ?? 'Prefetcher';
  }

  debug(message: string): void {
    hilog.debug(DOMAIN, TAG, FORMAT, this.getLogText(message));
  }

  info(message: string): void {
    hilog.info(DOMAIN, TAG, FORMAT, this.getLogText(message));
  }

  warn(message: string): void {
    hilog.warn(DOMAIN, TAG, FORMAT, this.getLogText(message));
  }

  private getLogText(message: string): string {
    return `[${this.messagePrefix}-${this.traceId}] ${message}`;
  }
}
